/** 
 * 自定义JS函数
 * */
 
 // var domain = 'http://tsh.jiuge_mc.com'; //默认域名
 var domain = 'http://tsh.fuzhuangchangongxiao.cn'; //云端域名
 var prefixUrl = ''; //页面地址前缀
 var sysKey = 'sysKey'; //参数键名,包含域名+接口权限等
 var appAccess = 'n7Q%U&PXHnAjWFB_bbfSgQRV&-ytc6:me$eRGGxVJcYTJV-c9YCC*W!&JNTC_-xRgJX3'; //APP接口权限
 var userInfo = ''; //用户信息
 var userInfoKey = 'userInfo'; //用户信息键名
 var indexList = 'indexList'; //首页数据键名
 var marketList = 'marketList'; //库数据键名
 var appVersionKey = 'appVersion'; //APP在本地的版本号键名
 var opinionList = 'opinionList'; //建议键名
 var signList = 'signList'; //签到键名
 var plusList = 'plusList'; //创单键名
 var boardList = 'boardList'; //创板键名
 var renderList = 'renderList'; //渲染作品键名
 var fileList = 'fileList'; //本地文件资源键名：
	/** 
	 * fileList 文件资源本地管理,数组列表
	 * 缓存名key、文件地址filePath、是否删除del【0/1】
	 * */
 // var imgTmp = prefixUrl+'./files/imgs/tmp.png'; //默认临时图片
 // var downMobilePath = '/storage/emulated/0/Android/data/io.dcloud.HBuilder/downloads/'; //手机下载文件的地址前缀
 // var downAppPath = '_downloads/'; //APP下载默认地址前缀
 
 
 
 
 /** 
  * 每天需要更新的
  * */
// 获取系统参数
function getSys(){
	//今天的年月日
	// var day = new Date();
	// var d = day.getFullYear().toString() + (day.getMonth()+1).toString() + day.getDate().toString();
	// var y = day.getFullYear();
	// var m = day.getMonth()+1;
	// var d = day.getDate();
	// if (m < 10) { m = '0'+m; }
	// var ymd = y + m + d;
	// mui.toast(ymd);
	var sys = cacheGet(sysKey);
	var sysVal;
	// 获取缓存的参数
	if (sys==null || sys.appAccess=='') { 
		sysVal = {
			domain:domain,
			appAccess:appAccess
		};
	} else {
		sysVal = {
			domain:sys.domain,
			appAccess:sys.appAccess
		};
	}
	cacheSet(sysKey, sysVal);
	return sysVal;
}
// 更新系统参数
function setSys(){
	var sys = getSys();
	if (!sys || !sys.domain) { return }
	// mui.toast(sys.domain)
	mui.ajax(sys.domain+'/app/sys/modify',{
		data:{
			appAccess:sys.appAccess
		},
		dataType:'json', //服务器返回json格式数据
		type:'post', //HTTP请求类型
		timeout:10000, //超时时间设置为10秒；
		// headers:{'Content-Type':'application/json'},
		headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
		success:function(res){
			// mui.toast('OK'+res.data.appVersion); return
			if (res.code!=0) {
				mui.toast('系统参数更新错误',{ 
					duration:'long', type:'div',
				});
				return
			}
			var sysVal = {
				domain:res.data.appDomain,
				appAccess:res.data.appAccess
			};
			cacheSet(sysKey,sysVal);
		},
		error:function(xhr,type,errorThrown){
			// console.log('网络错误');
			mui.toast('网络错误2',{ 
				duration:'long', type:'div',
			});
		}
	});
}
 
 
 
 
 
/** 
 * 缓存处理
 * */
//缓存获取
function cacheGet(key){
	var cacheStr = localStorage.getItem(key);
	var cache = JSON.parse(cacheStr);
	return cache;
}
//缓存设置
function cacheSet(key,val){
	//把数组转换为对象存入
	var str = JSON.stringify(val);
	localStorage.setItem(key,str);
	return true;
}
//缓存删除
function cacheDel(key){
    localStorage.removeItem(key);
}
//缓存删除
function cacheClear(){
    localStorage.clear();
}
 
 
 
 
 
 /** 
  * 页面跳转
  * */
function jumpToIndex(){ //首页
	mui.plusReady(function () {
		plus.webview.open(prefixUrl+"/index.html");
	});	
}
function jumpToMarket(){ //广场
	var tourl = prefixUrl+"/views/market.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToChat(){ //消息
	mui.plusReady(function () {
		plus.webview.open(prefixUrl+"/chat.html");
	});	
}
function jumpToMy(){ //我的
	mui.plusReady(function () {
		plus.webview.open(prefixUrl+"/views/my.html");
	});	
}
function jumpToMyAccount(){ //我的账号信息
	var tourl = prefixUrl+"/views/my/sets/account.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToIndexHistory(){ //首页历史
	var tourl = prefixUrl+"/views/index/ihistory.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToIndexOne(vid){ //首页历史单个
	var tourl = prefixUrl+"/views/index/ione.html?vid="+vid;
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMarketHistory(){ //库历史
	var tourl = prefixUrl+"/views/market/mhistory.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMarketOne(vid){ //首页历史单个
	var tourl = prefixUrl+"/views/market/mone.html?vid="+vid;
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToCamera(){ //拍链接
	var tourl = prefixUrl+"/views/my/pubs/camera.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyset(){ //我的设置
	var tourl = prefixUrl+"/views/my/myset.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMysetCache(){ //我的设置缓存
	var tourl = prefixUrl+"/views/my/sets/cache.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyZanList(){ //我的点赞列表
	var tourl = prefixUrl+"/views/my/zans/zlist.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyZanOneIndex(vid){ //我的点赞首页单个
	// vType:1首页2库
	var param = '?vid='+vid;
	var tourl = prefixUrl+"/views/my/zans/zonei.html"+param;
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyZanOneMarket(vid){ //我的点赞库单个
	var param = '?vid='+vid;
	var tourl = prefixUrl+"/views/my/zans/zonem.html"+param;
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyCollectList(){ //我的收藏列表
	var tourl = prefixUrl+"/views/my/collect/clist.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyCollectOneIndex(vid){ //我的收藏首页单个
	var param = '?vid='+vid;
	var tourl = prefixUrl+"/views/my/collect/conei.html"+param;
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyCollectOneMarket(vid){ //我的收藏库单个
	var param = '?vid='+vid;
	var tourl = prefixUrl+"/views/my/collect/conem.html"+param;
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyPlusList(){ //我的创作列表
	var tourl = prefixUrl+"/views/order/plus/plist.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyPlusOne(vid){ //我的创作单个
	var tourl = prefixUrl+"/views/order/plus/pone.html?vid="+vid;
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyBoardOne(pid){ //我的创板单个
	var tourl = prefixUrl+"/views/order/board/bone.html?pid="+pid;
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyRegist(){ //我的注册
	var tourl = prefixUrl+"/views/my/sets/regist.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyLogin(){ //我的登陆
	var tourl = prefixUrl+"/views/my/sets/login.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyNick(){ //我的用户名
	var tourl = prefixUrl+"/views/my/sets/nick.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyPwd(){ //我的密码
	var tourl = prefixUrl+"/views/my/sets/pwd.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyOpinionList(){ //我的建议列表
	var tourl = prefixUrl+"/views/my/opinion/list.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyOpinionAdd(){ //我的建议表单
	var tourl = prefixUrl+"/views/my/opinion/Add.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyHelp(){ //我的帮助
	var tourl = prefixUrl+"/views/my/help.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyScan(){ //我的扫一扫
	var tourl = prefixUrl+"/views/my/scan.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMyScanWeb(link){ //我的扫一扫页面
	var tourl = prefixUrl+"/views/my/scanWeb.html?url="+link;
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMySignList(link){ //我的签到列表
	var tourl = prefixUrl+"/views/my/signs/slist.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
function jumpToMySignAdd(link){ //我的签到新增
	var tourl = prefixUrl+"/views/my/signs/sadd.html";
	mui.plusReady(function () {
		plus.webview.open(tourl);
	});	
}
// 页面跳转数组
function jumpToView(){
	var views = [
		// 首页
		{
			"title":"首页",
			"icon":"home",
			"url":"/index.html"
		},
		// 库视频
		{
			"title":"库",
			"icon":download",
			"url":"/views/market.html"
		},
		// 我的
		{
			"title":"我的",
			"icon":"contact",
			"url":"/views/my.html"
		}
	];
}





/**
 * URL中，获取指定参数
 * paramName URL中需要获取的参数键名
 * */
function getUrlParam(paramName) {
    var url = document.location.toString();
    var arrObj = url.split("?");
    if (arrObj.length > 1) {
        var arrParam = arrObj[1].split("&");
        var arr;
        for (var i = 0; i < arrParam.length; i++) {
            arr = arrParam[i].split("=");
            if (arr != null && arr[0] == paramName) {
                return decodeURI(arr[1]);
            }
        }
        return "";
    }
    else {
        return "";
    }
}
/** 
 * 用js限制字数，超出部分以省略号...显示
 * str 字符串
 * num 显示的字数
 * */
function getStrLimitNum(str,num) {
    var strNew = '';
	if (str.length <= num) {
		strNew = str;
	} else {
		strNew = str.substr(0,num) + '...' ;
	}
	return strNew;
}